package com.heima.media.controller;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.WmNewsDto;
import com.heima.media.dto.WmNewsPageDto;
import com.heima.media.entity.WmNews;
import com.heima.media.entity.WmUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.media.service.IWmNewsService;

import java.util.List;
import java.util.Map;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 自媒体图文内容信息表 前端控制器
 * </p>
 *
 * @author ZC
 * @since 2022-06-30
 */
@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "自媒体图文内容信息表接口")
@CrossOrigin
public class WmNewsController {
    // http://localhost:8080/media/MEDIA/media/api/v1/news/list
    @Autowired
    private IWmNewsService wmNewsService;

    @PostMapping("/list")
    @ApiOperation(value = "listByCondition", notes = "自媒体文章列表")  // value =>指定名称   notes =>添加备注
    @ApiImplicitParam(name = "dto", value = "WmNewsPageDto", required = true) //required =>参数是否必填
    public ResponseResult listByCondition(@RequestBody WmNewsPageDto dto) {
        return wmNewsService.listByCondition(dto);
    }

    //请求网址: http://localhost:8080/media/MEDIA/media/api/v1/news//5281
    //请求方法: GET
    //状态代码: 404 Not Found
    //远程地址: 127.0.0.1:8080
    @GetMapping("/{id}")
    @ApiOperation(value = "listByCondition", notes = "自媒体文章列表")  // value =>指定名称   notes =>添加备注
    @ApiImplicitParam(name = "dto", value = "WmNewsPageDto", required = true) //required =>参数是否必填
    public ResponseResult getById(@PathVariable("id") Integer id) {
        WmNews wmNews = wmNewsService.getById(id);
        return ResponseResult.okResult(wmNews);
    }

    @PostMapping("/submit")
    @ApiOperation(value = "submit", notes = "自媒体新增文章")  // value =>指定名称   notes =>添加备注
    @ApiImplicitParam(name = "wmNewsDto", value = "WmNewsPageDto", required = true) //required =>参数是否必填
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto) {
        return wmNewsService.submit(wmNewsDto);
    }

    //@RequestBody  页面传输 时为接送格式的数据时使用
//@PathVariable   基本类型的数据 /{id}
//文章的上下架
    @PutMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto) {
        return wmNewsService.downOrUp(dto);
    }
}